import request from '@/utils/request'
import {
  getToken
} from '@/utils/auth'
import {
  param
} from '@/utils/index'

export function pagingMemberRoleAuthority(query) {
  return request({
    url: '/user/memberRoleAuthority/pagingMemberRoleAuthority',
    method: 'get',
    params: query
  })
}

// 主播管理分页
export function pagingAnchorManage(query) {
  return request({
    url: '/user/memberRoleAuthority/pagingAnchorManage',
    method: 'get',
    params: query
  })
}

// 主播管理导出
export function doExportAnchorManage(query) {
  return process.env.BASE_API + '/user/memberRoleAuthority/doExportAnchorManage?' + param(query) + '&accessToken=' +
    getToken()
}

// 统计各状态主播/供应商数量
export function statisticsStatus(query) {
  return request({
    url: '/user/memberRoleAuthority/statisticsStatus',
    method: 'get',
    params: query
  })
}

// 统计各微客状态数量
export function statisticsWholesaleRoleAuthorityByNature(query) {
  return request({
    url: '/user/memberRoleAuthority/statisticsWholesaleRoleAuthorityByNature',
    method: 'get',
    params: query
  })
}

// 批量更新申请、权限状态，根据微客id或主键id集合
// enterpriseId：企业id
// roleType：微客角色类型：1-批发商，2-主播
// roleAuthorityIds：角色权限表主键id集合 , roleAuthorityIds = []
// memberIds：微客id集合，memberIds = []
// status：状态：1审核通过 2审核未通过 100 作为清退操作状态，等同于 拒绝。只要是为了修改清退时间
// relationPlatform：关联平台 1：微信 2：抖音 3：快手，可为空
// reason：拒绝原因，可为空
export function updateBatchStatus(enterpriseId, roleType, roleAuthorityIds, memberIds, status, relationPlatform,
  reason) {
  var query = {
    enterpriseId: enterpriseId,
    memberRoleType: roleType,
    applyStatus: status,
    rejectReason: reason,
    relationPlatform: relationPlatform
  }
  if ((memberIds === undefined || memberIds === null || memberIds.length <= 0) && (roleAuthorityIds === undefined ||
      roleAuthorityIds === null || roleAuthorityIds.length <= 0)) {
    console.log('主键或微客id集合，都为空了!')
    return
  }
  query.memberIds = memberIds
  query.roleAuthorityIds = roleAuthorityIds
  return request({
    url: '/user/memberRoleAuthority/updateBatchStatus',
    method: 'post',
    data: query
  })
}
// 批量修改批发商等级
// enterpriseId：企业id
// roleAuthorityIds：角色主键id集合，和 memberIds 必须传一个值
// memberIds：微客id集合，和 roleAuthorityIds 必须传一个值
// wholesalerGrade：等级id
export function updateBatchWholesalerGrade(enterpriseId, roleAuthorityIds, memberIds, wholesalerGrade) {
  if (!roleAuthorityIds) {
    roleAuthorityIds = []
  }
  if (!memberIds) {
    memberIds = []
  }
  var query = {
    enterpriseId: enterpriseId,
    roleAuthorityIds: roleAuthorityIds,
    memberIds: memberIds,
    wholesalerGrade: wholesalerGrade
  }
  return request({
    url: '/user/memberRoleAuthority/updateBatchWholesalerGrade',
    method: 'post',
    data: query
  })
}
// 开启关闭微客角色权限
export function openOrCloseMemberRoleAuchority(query) {
  return request({
    url: '/user/memberRoleAuthority/saveOpenOrCloseMemberRoleAuchority',
    method: 'post',
    data: query
  })
}

/**
 * 获取企业主播管理提示 0: 关闭  1：开启
 */
export function getAnchorManageHint(enterpriseId) {
  return request({
    url: '/user/memberRoleAuthority/getAnchorManageHint',
    method: 'get',
    params: {
      enterpriseId
    }
  })
}

/**
 * 获取企业总部招募主播码
 */
export function doGetAnchorWxaCode(enterpriseId) {
  return request({
    url: '/user/memberRoleAuthority/doGetAnchorWxaCode',
    method: 'get',
    params: {
      enterpriseId
    }
  })
}

/**
 * 更新企业主播管理提示 0：今日不显示 1：永久关闭
 */
export function updateAnchorManageHint(enterpriseId, hintSelectStatus) {
  return request({
    url: '/user/memberRoleAuthority/updateAnchorManageHint',
    method: 'get',
    params: {
      enterpriseId,
      hintSelectStatus
    }
  })
}

/**
 * 更新企业主播自动授权提示 0：今日不显示 1：永久关闭
 */
export function updateAnchorAutoAuthorityHint(enterpriseId, hintSelectStatus) {
  return request({
    url: '/user/memberRoleAuthority/updateAnchorAutoAuthorityHint',
    method: 'get',
    params: {
      enterpriseId,
      hintSelectStatus
    }
  })
}

export function statisticsByWholesalerGrade(enterpriseId) {
  return request({
    url: '/user/memberRoleAuthority/statisticsByWholesalerGrade',
    method: 'get',
    params: {
      enterpriseId
    }
  })
}
